let main=document.querySelector('.main')
let xhr =new XMLHttpRequest()
xhr.open('get','http://chst.vip:1234/api/getinlanddiscount',true)
xhr.onload=function(){
    if(xhr.status===200){
        let res =JSON.parse(xhr.responseText)
        let an=res.result
        let lis=''
        console.log(an);
        an.forEach(item => {
            lis+=`
            <div class="maina" productId=${item.productId}>
                ${item.productImg}
                <p>${item.productName}</p>
                <p>${item.productPrice}</p>
                <p>${item.productFrom}|${item.productTime}</p>
            </div>
            `  
        });
        main.innerHTML=lis   
     
    }
}
xhr.send(null)

main.onclick=function(e){
    var e = e || window.event;
    var target = e.target || e.srcElement;
    if(target.nodeName==='DIV' || target.nodeName==='P' || target.nodeName==='IMG')
    // console.log(target.parentNode.getAttribute('productId'));
    console.log(target.parentNode);
    localStorage.setItem('productid',target.parentNode.getAttribute('productId'))
    location.href = 'http://127.0.0.1:5500/js/day18/html/domestic.html';
   
}
